package com.jsjvm.server.dbgproxy.jdwp.cmdsets;

import java.io.IOException;

import com.jsjvm.server.dbgproxy.JDWPCommandSet;
import com.jsjvm.server.dbgproxy.jdwp.data.JDWPInputStream;
import com.jsjvm.server.dbgproxy.jdwp.data.JDWPOutputStream;
import com.jsjvm.server.dbgproxy.jdwp.data.JDWPRequestHeader;
import com.jsjvm.shared.vmcmds.VMCommand;

@SuppressWarnings("serial")
public class JDWPMethodCommandSet extends JDWPCommandSet {
    private static final int LINE_TABLE_CMD				= 1;
    private static final int VARIABLE_TABLE_CMD			= 2;
    private static final int BYTECODE_CMD				= 3;
    private static final int IS_OBSOLETE_CMD				= 4;
    private static final int VARIABLE_TABLE_GENERIC_CMD	= 5;

	public static final int METHOD_SET = 6;

	@Override
	public int getCommandSetNumber() {
		return METHOD_SET;
	}

	public JDWPMethodCommandSet() {
		this.put(IS_OBSOLETE_CMD, new IsObsolete());
		this.put(VARIABLE_TABLE_GENERIC_CMD, new VariableTableGeneric());
		this.put(BYTECODE_CMD, JDWPCommandSet.getNIHandler());
	}

	/**
	 * Since we do not replace classes, they are never obsolete
	 */
	private static class IsObsolete extends JDWPCommandHandler {
		@Override
		public VMCommand handleCommand(JDWPRequestHeader hdr, JDWPInputStream is,
				JDWPOutputStream os) throws IOException {
			os.appendByte((byte) 0);
			os.commitReplyPacket(hdr);
			return null;
		}
	}
	/**
	 * Since we do not replace classes, they are never obsolete
	 */
	private static class VariableTableGeneric extends JDWPCommandHandler {
		@Override
		public VMCommand handleCommand(JDWPRequestHeader hdr, JDWPInputStream is,
				JDWPOutputStream os) throws IOException {
			os.replyWithError(hdr, ABSENT_INFORMATION);
			return null;
		}
	}
}
